<template>
  <div>
    <a-button  type="primary" :disabled="fileList.length === 0 || uploadIsOk" :loading="btninfo.loading" @click="handleUpload">
      {{ btninfo.loading ? '上传中' : '开始上传' }}
    </a-button>
  </div>
</template>
<script>
import moment from 'moment'
import {uploadFileFunction } from '@/api/public'
export default {
  props:['fileList','url','id','uploadIsOk','btninfo'],
  data() {
    return {
     uploading: false,   
    }
  },
  filters: {},
  created() {},
  mounted(){
  },
  computed: {},
  methods: {
    moment,
    //开始文件
    handleUpload() {   
      const { fileList } = this
      const formData = new FormData()
      fileList.forEach((file) => {
        formData.append('file', file)
      })
      this.$emit("btnChange",this.id)
      // this.uploading = true
      this.uploadingFileFunction(formData,this.url) 
    },

    //上传文件
    uploadingFileFunction(formData,url){
     uploadFileFunction(formData,url).then((response) => {
          if (response.code == 200) {
            let result = '上传成功'
            // this.uploading = false
            this.$emit("resultChange",result,this.id)
            this.$message.success('上传成功!')
          } else {
            console.log("失败")
            let result = `文件,上传失败:${response.msg}`
            // this.uploading = false
            this.$emit("resultChange",result,this.id)
            this.$message.error('上传失败!')
          }
        }) 
    }, 

  },
}
</script>
